package com.my.chapter11;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;


public class practice24 {
    static LinkedHashMap<String, Integer> a = new LinkedHashMap<>();
    static {
        a.put("Three", 3);
        a.put("Eight", 8);
        a.put("Nine", 9);
        a.put("ten", 10);
        a.put("one", 1);
    }

    public static void main(String[] args) {
        System.out.println(a);
        List<Map.Entry<String, Integer>> b = new ArrayList<Map.Entry<String,Integer>>(a.entrySet());
        Collections.sort(b, new Comparator<Map.Entry<String, Integer>>() {
            public int compare(Entry<String, Integer> c,Entry<String, Integer> d) {
                return c.getKey().compareTo(d.getKey());
            }
        });
        a.clear();
        for(Map.Entry<String, Integer> c:b) {
            a.put(c.getKey(), c.getValue());
        }
        System.out.println(a);
    }
}
